$(function () {
    let form = layui.form
    let layer = layui.layer
    form.verify({
        pwd: [
            /^[\S]{6,12}$/,
            '密码必须是6到12位且不能出现空格'
        ],
        newPwd: function (value) {
            let v1 = $('[name=oldPwd]').val()
            if (value === v1) {
                return '新密码不能和旧密码相同！'
            }
        },
        rePwd: function (value) {
            let v2 = $('[name=newPwd]').val()
            if (value !== v2) {
                return '两次密码输入不一致'
            }
        },
    })
    // 提交
    $('#formPwd').on('submit', function (e) {
        e.preventDefault();
        axios({
            method: 'POST',
            url: '/my/updatepwd',
            data: $(this).serialize()
        }).then(res => {
            if (res.data.status !== 0) {
                return layer.msg(res.data.message)
            }
            layer.msg(res.data.message)
            $('#formPwd')[0].reset()
            setTimeout(() => {
            window.parent.location.href = '/login.html'
            }, 1600);
        })
    })
    
})
